home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / file-tra / rdist-6.1 / rdist-6 / rdist-6.1.0-linuxpl2 / support / rdistcf.pl < prev    next >
Encoding:
Perl Script  |  1994-02-14  |  3.4 KB  |  144 lines

  1. #! /usr/usc/bin/perl
  2. #
  3. # $Id: rdistcf.pl,v 6.6 1992/12/02 22:45:56 mcooper Exp $
  4. #
  5. # compact-rdist-output: takes output of cooper's rdist and sorts 
  6. # it by host, producing a more compact report for casual perusal.
  7. #
  8. # Based on suggestions by J Greely.  code by Steve Romig.
  9.  
  10. # Basic idea: for each line of rdsit output (assumed to be of form
  11. # "host: message", record the list of hosts that it was seen on.  Sort
  12. # the messages in order of increasing number of hosts, and print a
  13. # report that lists each set of hosts and the messages that appeared for
  14. # those hosts, running from least number of hosts to the greatest.
  15. #
  16. # In other words, if rdist was run on bird, tree, fish and fruit, the
  17. # output might look something like this:
  18. #
  19. # fish:
  20. #     installing /export/local/bin/less
  21. #
  22. # bird tree fruit:
  23. #     updating /export/local/bin/less
  24. #
  25.  
  26. #
  27. # Format to use for printing the start of the report.
  28. #
  29. format STDOUT =
  30. user:        @<<<<<<<<<<<<<<<<<<<<<<<<<
  31.              $user
  32. directories: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  33.          $dirs
  34. ~~           ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  35.          $dirs
  36. hosts:         ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  37.              $hosts
  38. ~~           ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  39.              $hosts
  40. .
  41.  
  42. #
  43. # Format to use for body
  44. #
  45. format BODY = 
  46. ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
  47. $host_string
  48. @*
  49. $host_data
  50.  
  51. .
  52.  
  53. #
  54. # Use this to sort the lists of hosts by increasing number of hosts.
  55. #
  56. sub increasing {
  57.     $host_number{$a} <=> $host_number{$b};
  58. }
  59.  
  60. if ($#ARGV == 2) {
  61.     $user = shift(@ARGV);
  62.     $dirs = shift(@ARGV);
  63.     $hosts = shift(@ARGV);
  64.     write;
  65.     print "\n";
  66. } elsif ($#ARGV != -1) {
  67.     die "usage: compact-rdist-output [user dirs hosts]\n";
  68. }
  69.  
  70. #
  71. # read lines of rdist output, deal with the types of messages that 
  72. # appear
  73. #
  74. $lineno = 0;
  75. while (<>) {
  76.     #
  77.     # ignore these
  78.     #
  79.     next if /: updating of /;
  80.     next if /: updating host /;
  81.     next if /^updating /;
  82.     next if /^notify /;
  83.     #
  84.     # if it's a host: line, save it...
  85.     #
  86.     if (/^(\S+):[ \t]+(.*)$/) {
  87.     $data = $2;
  88.     if (defined($seen{$data})) {
  89.         $seen{$data} .= " $1";
  90.     } else {
  91.         $seen{$data} = $1;
  92.     }
  93.     #
  94.     # otherwise print it at the top of the report
  95.     #
  96.     } else {
  97.     print "$_\n";
  98.     }
  99. }
  100.  
  101. #
  102. # for each distinct message, work out the list of hosts that it 
  103. # appeared on (sorted in alphabetical order) and update the 
  104. # report text for that list of hosts.
  105. #
  106. foreach $line (keys %seen) {
  107.     @host_list = sort split(/ /, $seen{$line});
  108.     $host_string = join(' ', @host_list);
  109.     $seen{$line} = $host_string;
  110.  
  111.     #
  112.     # save the number of hosts in this list - use that for 
  113.     # sorting the report later
  114.     #
  115.     $host_number{$host_string} = $#host_list;
  116.     #
  117.     # append this message to the text for this list of hosts
  118.     #
  119.     $host_text{$host_string} .= "    " . $line . "\n";
  120. }
  121.  
  122. $: = " \n";    # Break characters
  123. $~ = BODY;    # Format to use
  124.  
  125. #
  126. # sort the host lists by increasing number, and print the 
  127. # report for each.  The text data is sorted numerically by
  128. # line number.
  129. #
  130. foreach $host_string (sort increasing keys %host_number) {
  131.     #
  132.     # Split the text data into an array, then do a sort
  133.     # and put the result back into a normal string variable.
  134.     #
  135.     $host_data = join("\n", sort split(/\n/, $host_text{$host_string}));
  136.  
  137.     # print the data
  138.     write;
  139. }
  140.  
  141. exit 0;
  142.  
  143.